package Simulator;

import Shared.Telephone;

public class Witness implements Runnable {

	private static final double randomFactor = 0; // XXX Now the witness sees
													// everything
	// away.

	private EnvironmentDatabase db;

	/**
	 * Create a Witness.
	 */
	public Witness() {
		db = EnvironmentDatabase.getInstance();
	}

	/**
	 * Looks at the environment and calls the emergency line whenever it sees an
	 * emergency.
	 */
	public void run() {
		Thread.currentThread().setName("Witness");
		try {
			while (true) {

				for (ER current : this.db.getAllER())
					if (Math.random() > randomFactor)
						Telephone.call(current);

				Thread.sleep(100);

			}
		} catch (InterruptedException e) {
			Thread.currentThread().interrupt();
		}
	}

}
